< previous page page_355 next page >

Page 355
Handling Multiple Control Selections
As you may recall from the "Implementing the SelectionChanged Event Procedure" section, the SelectedControls collection object represents all the controls that the developer has selected when he or she displays the Property Pages. You use the SelectedControls object in the SelectionChanged and ApplyChanges event procedures to access the properties of each selected control. For example, if the developer has two Calculator controls selected, SelectedControls(0).Caption represents the first control's caption, and SelectedControls(1).Caption represents the caption of the second control. If you write the code appropriately, the developer can apply the same caption to both selected Calculator controls.
You might not want to apply some properties, such as the Operation property, to multiple selected controls. In this case, you can use the Count property of the SelectedControls collection to see whether you should ignore the change or even set the Visible property of a control on the Property Page to False.
Another way to handle this situation would be to apply only certain changes to all controls and others to only the first control. A sample ApplyChanges event that handles multiple controls is shown in Listing 15.8.
Listing 15.8 CALC.ZIPApplying Changes to Multiple Controls
Private Sub PropertyPage_ApplyChanges()

    Dim control As CalcControl

    'Set Captions for every control
    For Each control In SelectedControls
        control.Caption = txtCaption
        control.ButtonCaption = txtButtonCaption
    Next control

    'Set only the first control's Operation property
    SelectedControls(0).Operation = cmbOperation.ListIndex

End Sub
To test this procedure, first open the Property Pages dialog box. Next, highlight multiple instances of the Calculator control, and change their properties.
Control Error Handling
The importance of controls running correctly cannot be overstated. Developers and users are depending on using the control as a self-contained, robust object that does not crash under unusual conditions. The developer is, of course, responsible for testing that the application runs correctly with your control, but you can take several precautions to help ensure your controls don't present developers and users with any nasty surprises.
sarrow.gifSee "Packaging ActiveX Components," p. 788

 
< previous page page_355 next page >